<?php

namespace Tbf\Bundle\DatabaseBundle\ListQuery;

use Doctrine\ORM\QueryBuilder;
use Tbf\Bundle\SerializerBundle\Serializer;
use Tbf\Component\Arrays\ArrayFunction;

class ListQueryManager
{
    protected $serializer;
    public function __construct(Serializer $serializer=null)
    {
        $this->serializer = $serializer;
    }

    /**
     * @return ListQueryHandler
     */
    public function create()
    {
        return new ListQueryHandler($this->serializer);
    }

    /**
     * 最常见操作简化,
     * 返回对象接口
     * @param $qb
     * @param $input
     * @return array
     * func(qb QueryBuilder,input struct{list_query ListQueryArray})(data []obj,total int)
     */
    public function getPageResultByOrmQbAndListQueryInput(QueryBuilder $qb,$input){
        return $this->create()
            ->fromOrmQueryBuilder($qb)
            ->fromListQueryArray(ArrayFunction::defaultParameter($input,'list_query',array()))
            ->getPageResult();
    }
}
